package com.myself.cloud.service.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.myself.cloud.api.IMyselfUserService;
import com.myself.cloud.entity.bean.MyselfUser;
import com.myself.cloud.service.mapper.MyselfUserMapper;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * @auther baijialiang
 * @create 2022-09-01
 * @describe 服务实现类
 */
@Service
public class MyselfUserServiceImpl extends ServiceImpl<MyselfUserMapper, MyselfUser> implements IMyselfUserService,
        UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_name", s);
        MyselfUser myselfUser = getOne(queryWrapper);
        if (myselfUser != null) {
            return new User(myselfUser.getUserName(), myselfUser.getUserPassword(), new ArrayList<>());
        }
        return new User("", "", new ArrayList<>());
    }
}
